package com.abbas.smartCity.ui.parkingWhere;

import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.abbas.smartCity.App;
import com.abbas.smartCity.R;
import com.abbas.smartCity.base.BaseActivity;
import com.abbas.smartCity.bean.parkingWhereBean.ParkingDetail;
import com.abbas.smartCity.retroft.ICallback;
import com.bumptech.glide.Glide;

import retrofit2.Call;

public class ParkingDetailActivity extends BaseActivity {

    private int id;

    private ImageView im;
    private TextView name;
    private TextView tag1;
    private TextView tag2;
    private TextView tag3;
    private TextView tag4;
    private Button back;


    @Override
    protected int getLayoutId() {
        return R.layout.activity_parking_detail;
    }

    @Override
    protected String setCustomTitle() {
        return "停车场详情";
    }

    @Override
    protected void initView() {
        im = (ImageView) findViewById(R.id.im);
        name = (TextView) findViewById(R.id.name);
        tag1 = (TextView) findViewById(R.id.tag1);
        tag2 = (TextView) findViewById(R.id.tag2);
        tag3 = (TextView) findViewById(R.id.tag3);
        tag4 = (TextView) findViewById(R.id.tag4);
        back = (Button) findViewById(R.id.back);
    }

    @Override
    protected void initData() {
        id = getIntent().getIntExtra("id", -1);

        api.getParkingDetail(id).enqueue(new ICallback<ParkingDetail>() {
            @Override
            public void onSuccess(Call<ParkingDetail> call, ParkingDetail parkingDetail) {
                final ParkingDetail.DataBean data = parkingDetail.getData();
                Glide.with(ParkingDetailActivity.this)
                        .load(App.getBaseUrl() + data.getImgUrl())
                        .error(R.drawable.ic_baseline_broken_image_24)
                        .into(im);

                name.setText(data.getParkName());
                tag1.setText("地址：" + data.getAddress());
                tag2.setText("距离：" + data.getDistance());
                tag3.setText("空位个数：" + data.getVacancy());
                tag4.setText("收费/小时：" + data.getRates());
            }
        });
    }

    @Override
    protected void initEvent() {
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ParkingDetailActivity.this.finish();
            }
        });
    }
}